package hander

import (
	"github.com/gin-gonic/gin"
	"redbook/api/reponse"
	"redbook/api/request"
	"redbook/internal/dao"
	"redbook/internal/models"
)

func Update(c *gin.Context) {
	req := request.RedBook{}
	if err := c.ShouldBind(&req); err != nil {
		reponse.ErrorRouth(c, "绑定失败")
		return
	}
	user := models.RedBook{
		Title:   req.Title,
		Content: req.Content,
		Image:   req.Image,
	}
	if err := dao.Add(&user); err != nil {
		reponse.ErrorRouth(c, "添加失败")
		return
	}
	reponse.SuccessRouth(c, "添加成功", user.ID)
}
func List(c *gin.Context) {
	req := request.RedBook{}
	if err := c.ShouldBind(&req); err != nil {
		reponse.ErrorRouth(c, "绑定失败")
		return
	}
	user := models.RedBook{}
	if err := dao.List(&user); err != nil {
		reponse.ErrorRouth(c, "展示失败")
		return
	}
	reponse.SuccessRouth(c, "展示成功", user)
}
func Dian(c *gin.Context) {
	req := request.RedBook{}
	if err := c.ShouldBind(&req); err != nil {
		reponse.ErrorRouth(c, "绑定失败")
		return
	}
	user := models.RedBook{
		Title:   req.Title,
		Content: req.Content,
		Image:   req.Image,
	}
	if err := dao.Add(&user); err != nil {
		reponse.ErrorRouth(c, "点赞失败")
		return
	}
	reponse.SuccessRouth(c, "点赞成功", user.ID)
}
